"""
@name : 面向对象
@author : shiyaling
@projectname : xsfh
"""
#迭代器
#__iter__  方法返回自身
#   return self
#__next__  返回下一个值
#最后实例化成一个迭代器对象 斐波那契数列

# class Fibonacci():
#     def __init__(self,max):
#         self.num1 = 0
#         self.num2 = 1
#         self.max = max
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         self.num1 = self.num2
#         self.num2 = self.num1 + self.num2
#         if self.num2 <= self.max:
#             return self.num2
#         else:
#             raise StopIteration
#
# max = int(input("请输入最大值："))
# test = Fibonacci(max)
# for i in test:
#     print(i)

#自定义异常类  -- 继承exception
class ListError(Exception):
    def __init__(self,list,message):
        self.list = list
        self.message = message
    def __str__(self):
        msg = "列表" + str(self.list) + self.message
        return msg

try:
    lst = [1,2,3,4,5,6,7,8,9,2,3]
    if len(lst) > 10:
        raise ListError(lst,"长度超过10")
except ListError as e:
    print("ListError",e)





